/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * StructureNetwork
 * Copyright (C) Michele Vidotto 2008 <vid1998@email.it>
 * 
 * StructureNetwork is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * StructureNetwork is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _STRUCTURENETWORK_H_
#define _STRUCTURENETWORK_H_


#include <vector>
#include <string>
#include <GetArg.h>
#include <PdbLoader.h>
#include <Spacer.h>
#include <AminoAcidCode.h>
#include <sys/stat.h>
#include <sys/types.h> 
#include <dir.h>

using namespace std;
using namespace Biopool;


class StructureNetwork 
{	
//------------------------------------------------------------------------------
	protected:
	
	struct HBonds
	{
		HBonds();
		bool 	is_main;
		int 	don_num;
		int 	acc_num;
		char 	don_code;
		char 	acc_code;
		string 	atom_don_code;
		string 	atom_acc_code;
		double 	h_bond_length;
		double 	h_bond_angle;
	};
		
	struct SaltBridge
	{	
		SaltBridge();
		int	positive_num;
		int negative_num;
		char positive_code;
		char negative_code;
		string 	atom_negative_code;
		string 	atom_positive_code;
		double bridge_length;
		double bridge_angle;
	};
		
	struct DisulfideBond
	{	
		DisulfideBond();
		double bond_length;
		double xss_angle;
	};
		
	//Definizione struttura dati con cui riempio ogni casella matrice
	
	struct TypeOfConnection
	{
		TypeOfConnection();
	
		char 	aa_i_code; //codice aminoacidico ad una lettera
		char 	aa_j_code; //codice aminoacidico ad una lettera
		string 	atom_i_code; //codice atomico a più lettere
		string 	atom_j_code; //codice atomico a più lettere
		double 	distance;	//distanza che determina il contatto
		bool 	is_h_bond; //presenza o meno di legame ad H tra gli aa definiti in contatto
		bool	is_salt_bridge; //presenza o meno di ponte salino
		bool	is_disulfide_bond;
		vector <HBonds> h_bonds; //vettore contenente caratteristiche legami ad H
		vector <SaltBridge> salt_bridge;
		vector <DisulfideBond> disulfide_bond;
	};	

//------------------------------------------------------------------------------

	public:
	
//costruttore
	StructureNetwork(string);
//distruttore	
	virtual ~StructureNetwork(){}
		
//metodi pubblici---------------------------------------------------------------		
	void SetMaxDistanceOfAlpha(double);

	double GetMaxDistanceOfAlpha() const;
		
	void SetMaxDistanceOfClosest(double);
		
	double GetMaxDistanceOfClosest() const;
	
	TypeOfConnection GetDistanceMatrix(int, int) const;
	
	void PrintCytoscapeFiles(bool);
		
	void CalculateCAlphaDistance();
		
	void CalculateClosestAtomDistance();
	
	void SetAlpha(bool);
	
	void SetClosatom(bool);
		
	int ImportHydrogenBond(string);
		
	void CalculateSaltBridge();
		
	void CalculateDisulfideBond();		
		
//------------------------------------------------------------------------------
	
	private:

	//Carica un file pdb su uno spacer
	bool SetInputFile(string);
	void LoadSpacer();
	void EraseMatrixOfDistance();
	void EraseHbons();
	void EraseSaltBridge();
	void EraseDisulfideBond();
		
	void ClosestPrintFilesAllHbonds(string, string, string, string, string, 
					string, string, string, string, string, 
					string, string, string, string, string, string, string,
					string, string, string, string);
		
	void AlphaPrintFilesAllHbonds(string, string, string, string, string, 
					string, string, string, string, string, 
					string, string, string, string, string, string, string,
					string, string, string, string);
		
	void ClosestPrintFiles(string, string, string, string, string, 
					string, string, string, string, string, 
					string, string, string, string, string, string, string,
					string, string, string, string);
		
	void AlphaPrintFiles(string, string, string, string, string, string,
						 string, string, string, string, string);
		
	double MyRound (double, int);
		
	vgVector3<double> CalculateMassCenter(int&, char);
	
	double CalculateSaltAngle(int&, int&, char, char);
		
	double CalculateSaltDistance(int&, int&, char, char);
		
	double CalculateDisulfideXssAngle(int&, int&);
		
	string GetTime();
	
	void PrintReport(string);
		
//Dati membro-------------------------------------------------------------------

	double max_distance_of_alpha;
	double max_distance_of_closest;	
	string input_file_path;
	string input_file_dir;
	bool alpha, closatom;
	vector <vector <TypeOfConnection> > distance_matrix;
	Spacer sp;
};

#endif // _STRUCTURENETWORK_H_
